Looking for Haskell `group` alternative in F#
Posted
by
Heather
on Stack Overflow
See other posts from Stack Overflow
or by Heather
Published on 2014-05-29T07:37:43Z
Indexed on
2014/05/29
21:28 UTC
Read the original article
Hit count: 127
Haskell group
descripted there: http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html#v:group
example :
group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"]
Is there simple F# way of doing it?
I can implement something alike
let rec sameCounter (data : list<float>) el same (ss : list<float * int>) =
if data.Length > (el + 1) then
if data.[el] = data.[el + 1] then
sameCounter data (el + 1) <| same + 1 <| ss
else if same > 0 then sameCounter data (el + 1) <| 0 <| (data.[el], same) :: ss
else sameCounter data (el + 1) <| 0 <| ss
else ss
let group d = sameCounter d 0 0 []
but it's a bit ugly way I think, is there better variant?
© Stack Overflow or respective owner